// Copyright (C) ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
//
// $Id: child_node.cpp 209 2008-08-28 10:05:39Z heavyzheng $
//

#ifndef ZZHENG_XML_SOURCE
#define ZZHENG_XML_SOURCE
#endif // ZZHENG_XML_SOURCE

#include <zzheng/xml/dom/libxml2/child_node.hpp>
#include <zzheng/xml/dom/libxml2/utility.hpp>

#include <libxml/tree.h>
#include <string>

namespace zzheng {
namespace xml {
namespace dom {
namespace libxml2_ {

    child_node::child_node(xmlNode* px): node(px) {
        // Do nothing.
    }

    child_node::~child_node() {
        // Do nothing.
    }

    basic_node_ptr<child_node> child_node::prev_sibling() {
        return basic_node_ptr<child_node>( const_cast<child_node*>(prev_sibling_()) );
    }

    basic_node_ptr<child_node> child_node::next_sibling() {
        return basic_node_ptr<child_node>( const_cast<child_node*>(next_sibling_()) );
    }

    basic_node_ptr<const child_node> child_node::prev_sibling() const {
        return basic_node_ptr<const child_node>( prev_sibling_() );
    }

    basic_node_ptr<const child_node> child_node::next_sibling() const {
        return basic_node_ptr<const child_node>( next_sibling_() );
    }

    const child_node* child_node::prev_sibling_() const {
        if (raw()->prev != 0) {
            return static_cast<const child_node*>(raw()->prev->_private);
        } else {
            return 0;
        }
    }

    const child_node* child_node::next_sibling_() const {
        if (raw()->next != 0) {
            return static_cast<const child_node*>(raw()->next->_private);
        } else {
            return 0;
        }
    }

} // namespace zzheng::xml::dom::libxml2_
} // namespace zzheng::xml::dom
} // namespace zzheng::xml
} // namespace zzheng



